package homework.yuandan.service.impl;

import homework.yuandan.beans.ActionRight;
import homework.yuandan.common.ResponseEnum;
import homework.yuandan.common.vo.ResultVO;
import homework.yuandan.exception.AppException;
import homework.yuandan.mapper.ActionRightMapper;
import homework.yuandan.mapper.RoleMapper;
import homework.yuandan.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作者:49293
 * 时间:2021/1/6-15:31
 *
 * @author 49293
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Resource
    RoleMapper roleMapper;
    @Resource
    ActionRightMapper actionRightMapper;

    @Override
    public List<String> selectRightCodeByRoleId(Integer roleId) {
        return roleMapper.selectRightCodeByRoleId(roleId);
    }

    @Override
    public ResultVO<List<ActionRight>> selectByRoleId() {
        List<ActionRight> actionRights = actionRightMapper.selectByRoleId();
        if (actionRights.size() == 0) {
            throw new AppException(ResponseEnum.ROLE_RIGHT_EMPTY);
        }

        return new ResultVO<>(ResponseEnum.SUCCESS_SERVER, actionRights);
    }
}
